 /*
    *  Copyright 2004 Thevert Liu  <thevert.liu@gmail.com>
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
    *  You may obtain a copy of the License at
    *
    *      http://www.apache.org/licenses/LICENSE-2.0
    *
   *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */

#include <TypeTrans.h>
#include <map>

class StrValueCache
{
public:
    template<typename T> 
    bool set(const std::string& key, const T& val) {
        std::string sv ;
        if (!TypeTrans<T>::V2S(val, sv))  return false ;
        mCache[key] = sv ;
    }
    
    template<typename T> 
    bool get(const std::string& key, T& val) {
        return TypeTrans<T>::S2V(mCache[key], val) ;
    }
    
    bool set(const std::string& key, const std::string& val) {
        mCache[key] = val ;
    }
    
    bool get(const std::string& key, std::string& val) const {
        val = ((StrValueCache*)this)->mCache[key] ;
        return true ;
    }
    
    
private:
    
    std::map<std::string, std::string> mCache ;    
    
} ;


